<template>
  <div class="">
    <div class="body">
      <div class="body-content">
        <el-card class="box-card">
          <el-collapse v-model="activeName" accordion>
            <el-collapse-item title="收藏夹" name="1">
              <ul v-if="collectMes.length > 0">
                <li
                  v-for="(cmItem,cmIndex) in collectMes"
                  :key="cmIndex"
                  @mouseenter="hoverCIndex = cmIndex"
                  @mouseleave="hoverCIndex = -1"
                  class="praise-li">
                  <div class="praise-li-dv">
                    <img :src="cmItem.img" alt="" class="praise-li-img">
                    <div class="praise-li-title">
                      <h3 class="plnpra-nickname">{{cmItem.title}}</h3>
                      <h5>{{cmItem.time}}</h5>
                      <div  @click="cancel(cmItem.dataCollectId)" class="cancelPraise" :class="{'link-item-hover':cmIndex==hoverCIndex}">
                        <img src="/static/img/tubiao/取消.png" alt="" class="praise-li-tubiao">
                        <span>取消收藏</span>
                      </div>
                    </div>
                    <span class="praise-li-content" :title="cmItem.content" @click="to('/details',cmItem.data_id)">{{cmItem.content}}</span>
                  </div>
                  <el-divider></el-divider>
                </li>
              </ul>
              <div v-else @click="go('/home')" style="text-align:center;"><i class="iconfont icon-meiyoushuju"></i>还没有收藏哦，快去收藏看看</div>
            </el-collapse-item>
          </el-collapse>
        </el-card>
      </div>
    </div>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        collectMes:[],
        activeName: '1',
        hoverCIndex:-1,
        isLogin:"",
        user_id:""
      }
    },
    mounted(){
      this.getCollect();

    },
    methods: {
      async getCollect(){
        this.isLogin = this.$store.getters.getShow;
        if(this.isLogin){
          this.user_id = this.$store.getters.getUser.user_id;
          console.log(this.user_id);
        }
        let user_id = this.user_id;
        const {data:collectRes} = await this.$http.post("selTCollect",{user_id});
        console.log(collectRes);
        if(collectRes.status != 200){
          this.$message.error('查询收藏情况失败');
        }else{
          this.collectMes = collectRes.message;
        }
      },
      go(path){
        this.$router.push(path)
      },
      to(path,id){
        this.$router.push({path:path,query:{id:id}})
      },
      async cancel(id){
        console.log(id);
        let variate = id;
        // let mesObj = JSON.stringify(item);
        const {data:res} = await this.$http.post("delCollectData",{variate});
        console.log(res);
        if(res.status != 200){
          this.$message.error('取消收藏失败');
        }else{
          this.$message({
          message: '取消收藏成功',
          type: 'success'
        });
        this.getCollect();
        }
      }
    }
  }
</script>
<style scoped>

@import url('./css/person.css');
</style>
